package everyday;

import java.util.stream.Collectors;

/**
 * @Author: Siantar
 * @Date: 2023-06-19-13:54
 * @Description: 1.0
 */
public class T1262 {
    public int maxSumDivThree(int[] nums) {
        int[] f = new int[]{0,Integer.MIN_VALUE,Integer.MIN_VALUE};
        for (int num : nums) {
            int []g=new int[3];
            System.arraycopy(f,0,g,0,3);
            for (int i = 0; i < 3; i++) {
                g[(i+num)%3]=Math.max(g[(i+num)%3],f[i]+num);
            }
            f=g;
        }
        return f[0];
    }
}
